package cn.oracle.eshop.cart.dao.impl;

import cn.oracle.eshop.cart.dao.ShoppingCartItemDAO;
import cn.oracle.eshop.cart.domain.ShoppingCartItemDO;
import cn.oracle.eshop.cart.mapper.ShoppingCartItemMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/** 购物车条目管理模块的DAO组件
 * @author wyh
 * @ClassName  ShoppingCartItemDAOImpl
 * @date 2022/3/28 /21:18
 */
@Slf4j
@Repository
public class ShoppingCartItemDAOImpl implements ShoppingCartItemDAO {
    @Autowired
    private ShoppingCartItemMapper shoppingCartItemMapper;
    /****
     * 新增购物车条目
     * @author wyh
     * @date 2022/2/14
     * @param shoppingCartItemDO 购物车条目DO对象
     * @return
     */
    @Override
    public Boolean saveShoppingCartItem(ShoppingCartItemDO shoppingCartItemDO) {
        try {
            shoppingCartItemMapper.saveShoppingCartItem(shoppingCartItemDO);
        } catch (Exception e) {
            log.error("error:{}",e);
            return false;
        }
        return true;
    }
    /***
     * @Descipon: 根据商品sku id查询购物车中是否存在商品条目
     * @author wyh
     * @date 2022/2/14
     * @param shoppingCartId 购物车ID
     * @param goodsSkuId 商品sku id
     * @return cn.oracle.eshop.cart.domain.ShoppingCartItemDO
     */
    @Override
    public ShoppingCartItemDO getShoppingCareItemByGoodsSkuId(Long shoppingCartId, Long goodsSkuId) {
        try {
            return shoppingCartItemMapper.getShoppingCareItemByGoodsSkuId(shoppingCartId,goodsSkuId);
        } catch (Exception e) {
            log.error("error:{}",e);

        }


        return null;
    }

    /***
     * 更新购物车条目
     * @author wyh
     * @date 2022/3/28
     * @param shoppingCartItemDO
     * @return void
     */
    @Override
        public Boolean updateShoppingCartItem(ShoppingCartItemDO shoppingCartItemDO) {
        try {
            shoppingCartItemMapper.updateShoppingCartItem(shoppingCartItemDO);
        } catch (Exception e) {
            log.error("error:{}",e);
            return false;
        }
        return true;
    }
}
